import React, { Component } from 'react'
import { Card } from 'antd'
//按需加载echarts
import echarts from 'echarts/lib/echarts'
import ReactEcharts from 'echarts-for-react';
//引入柱形图
import 'echarts/lib/chart/bar';


class Bar extends Component {
    componentWillMounut() {
        ReactEcharts
    }
    getOption = () => {
        let option = {
            color: ['#3398DB'],
            tooltip: {
                trigger: 'axis',
                axisPointer: {            // 坐标轴指示器，坐标轴触发有效
                    type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                }
            },
            title: {
                text: '用户骑行订单'
            },
            xAxis: {
                data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
            },
            yAxis: {
                type: 'value'
            },
            series: [
                {
                    name: '订单量',
                    type: 'bar',
                    data: [1000, 2000, 3000, 4000, 5000, 6000, 7000]
                }
            ]
        }
        return option
    }
    getOption_2 = () => {
        let option_2 = {
            color: ['#003366', '#006699', '#4cabce', '#e5323e'],
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    type: 'shadow'
                }
            },
            legend: {
                data: ['OFO', '摩拜', '小蓝']
            },
            toolbox: {
                show: true,
                orient: 'vertical',
                left: 'right',
                top: 'center',
                feature: {
                    mark: { show: true },
                    dataView: { show: true, readOnly: false },
                    magicType: { show: true, type: ['line', 'bar', 'stack', 'tiled'] },
                    restore: { show: true },
                    saveAsImage: { show: true }
                }
            },
            calculable: true,
            xAxis: [
                {
                    type: 'category',
                    axisTick: { show: false },
                    data: ['2012', '2013', '2014', '2015', '2016']
                }
            ],
            yAxis: [
                {
                    type: 'value'
                }
            ],
            series: [
                {
                    name: 'OFO',
                    type: 'bar',
                    barGap: 0,
                    data: [320, 332, 301, 334, 390]
                },
                {
                    name: '摩拜',
                    type: 'bar',
                    data: [220, 182, 191, 234, 290]
                },
                {
                    name: '小蓝',
                    type: 'bar',
                    data: [150, 232, 201, 154, 190]
                }
            ]
        }
        return option_2
    }
    render() {
        return (
            <div>
                <Card title="柱形图_1">
                    <ReactEcharts
                        option={this.getOption()}
                        theme="稻城"
                        style={{ height: 500 }}
                    />
                </Card>
                <Card title="柱形图_2">
                    <ReactEcharts
                        option={this.getOption_2()}
                        theme="稻城"
                        style={{ height: 500 }}
                    />
                </Card>
            </div>
        )
    }
}

export default Bar

